<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
	</body>
	<script type="text/javascript">
		let Event = {
			pond: {},
			on:function (eventName,fn) {
				if(this.pond[eventName]) {
					this.pond[eventName].push(fn)
				} else {
					this.pond[eventName] = []
					this.pond[eventName].push(fn)
				}
			},
			emit:function (eventName,msg) {
				this.pond[eventName].forEach(item => {
					item(msg)
				})
			},
			'test':()=>{
				//注意对象中一般不用箭头函数，因为箭头函数中的this
				//指向window
				console.log(this)  //window
			}
		}

		Event.on('event1', function(msg) {
			console.log('event1')
			console.log(msg)
		})
		Event.on('event1', function() {
			console.log('event1_2')
		})
		Event.on('event2', function() {
			console.log('event2')
		})

		setTimeout(() => {
			Event.emit('event1', 111)
		}, 1000)
		
		
		Event.test()
	</script>

</html>